import Vue from "vue";
import Vuex from "vuex";
import axios from "axios";

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    professionTypes: [],
    person: {
      username: "zhangsan",
      age: 18,
    },
  },
  mutations: {
    updateProfessionTypes(state, payload) {
      state.professionTypes = payload;
    },
    updatePerson(state, { name, age }) {
      state.person = { username: name, age: age };
    },
  },
  actions: {
    // getProfessionTypes( context, payload) {
    getProfessionTypes({ commit }, payload) {
      axios({
        method: "get",
        url: "/took/common/professionTypes",
      }).then(
        (res) => {
          console.log("res data :", res.data);
          //  state.professionTypes= res.data
          commit("updateProfessionTypes", res.data);
        },
        (error) => {
          console.log(" request error : " + error.response.status);
        }
      );
    },
  },
  modules: {},
});
